package com.ruoyi.common.oms.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.oms.entity.YytOmsOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单 Mapper 接口
 * </p>
 *
 * @author huangshun
 * @since 2021-12-16
 */
@Repository
public interface YytOmsOrderMapper extends BaseMapper<YytOmsOrder> {

    /**
     * 根据会员id和订单状态获取订单数量
     */
    @Select("select count(id) from yyt_oms_order where member_id = #{memberId} and `status` = #{status}")
    Integer countOrder(String memberId, int status);

    /**
     * 获取用户订单列表
     */
    @Select("select * from yyt_oms_order ${ew.customSqlSegment}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "itemList", column = "id",
                    many = @Many(select = "com.ruoyi.common.oms.dao.YytOmsOrderItemMapper.listByOrderId")),
            @Result(property = "returnList", column = "id", many = @Many(select = "com.ruoyi.common.oms.dao.YytOmsOrderReturnApplyMapper.listByOrderId"))
    })
    Page<YytOmsOrder> getOrders(@Param(Constants.WRAPPER) Wrapper<YytOmsOrder> wrapper, Page<YytOmsOrder> page);


    /**
     * 获取用户可售后列表
     */
    IPage<YytOmsOrder> getOrderReturns(Page<YytOmsOrder> page, String memberId);

    /**
     * 获取今日订单列表
     * @param wechatId
     * @return
     */
    Map getDayCountNumber(@Param("wechatId") String wechatId, @Param("dayDate") String dayDate);

    List<YytOmsOrder> getDayOrderList(@Param("shopList") List<String> shopList,@Param("dayDate") String dayDate);

    List<YytOmsOrder> getAwaitOrderCancels(@Param("shopList") List<String> myShopList);
}
